﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using 期末.Models.Database;

namespace 期末.Controllers
{
    [Route("/[action].html")]
    [Route("[controller]/[action]")]
    public class HomeController : Controller
    {
        private readonly newsContext _db;
        public HomeController(newsContext db)
        {
            _db = db;
        }
        public IActionResult Index(int cateid)
        {           
            var list = _db.Menus.ToList();
            ViewData["list"] = list;
            if (cateid == 0)
            {
                var news = _db.Xinwens.ToList();                
                ViewData["news"] = news;
            }
            else
            {
                var news = _db.Xinwens.Where(x => x.Id == cateid).ToList();
                ViewData["news"] = news;
            }
            return View();
        }
        public IActionResult Detail(int newsid)
        {
            var list = _db.Menus.ToList();
            ViewData["list"] = list;
            var news = _db.Xinwens.Where(x => x.Newid == newsid).ToList();
            ViewData["news"] = news;  
            return View();
        }
    }
}
